package com.lujieni.nio.c1;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * 集中写
 */
public class TestJiZhongWrite {

    public static void main(String[] args) {
        try (FileChannel channel = new RandomAccessFile("words2.txt", "rw").getChannel()) {
            ByteBuffer b1 = StandardCharsets.UTF_8.encode("abc");
            ByteBuffer b2 = StandardCharsets.UTF_8.encode("123");
            ByteBuffer b3 = StandardCharsets.UTF_8.encode("你好");
            channel.write(new ByteBuffer[]{b1, b2, b3});
        } catch (IOException e) {

        }
    }
}
